GBML manual / Constants

EASE_ELASTIC_IN_OUT

A spring at both ends: it winds up with growing wobbles, crosses the middle, then overshoots and wobbles round the end. The number goes about 12% outside the range at both ends.

Syntax

EASE_ELASTIC_IN_OUT: constant

Description

The "elastic in out" curve for tween and tween_to: a spring at both ends. It winds up with growing wobbles round the start, crosses the middle, then goes past the end and wobbles round it. After a quarter of the time it is at 0.01, after half exactly 0.50, and after three quarters at 0.99.

The number leaves the range

Most curves keep the number between from and to. This one does not, at either end. The wobbles go about 12% of the distance behind from and about 12% past to: a number tweened from 100 to 200 makes a few tiny wobbles, dips to about 88, crosses the middle, reaches about 212 and wobbles round 200 until it rests.

When the number is a position, that is the point. When the number has to stay in a range it is a problem, at both ends:

tween_to(volume, 100, 90, EASE_ELASTIC_IN_OUT);   // the volume dips below 0 and goes above 100: don't do this to a number with limits

For a number that must stay between its two ends, use a sine or quad curve, or a bounce, which never goes outside them. It does arrive exactly: after the end the number is exactly to, every frame.

A real capture, 27 frames played in a loop - three small graphs, one above the other, labeled in, out and in out. In each one a ball moves steadily to the right while its height on the screen is the number being tweened: a dim dashed line at the top is where the number starts, a green dashed line below it is where it ends, and a trail of dots shows where the ball has been. In the out row the ball shoots down past the green line by a long way and then wobbles up and down round it with smaller and smaller swings until it rests on it, like a spring let go. The in row is the same wobble the other way round: swings round the dim line that grow bigger, and then a drop onto the green line. The in out row winds up round the dim line, crosses the middle, and wobbles round the green line. The first frame, which is all a viewer that cannot animate shows, is the finished picture: every dot, drawing the whole of each curve.A real capture, 27 frames played in a loop - three small graphs, one above the other, labeled in, out and in out. In each one a ball moves steadily to the right while its height on the screen is the number being tweened: a dim dashed line at the top is where the number starts, a green dashed line below it is where it ends, and a trail of dots shows where the ball has been. In the out row the ball shoots down past the green line by a long way and then wobbles up and down round it with smaller and smaller swings until it rests on it, like a spring let go. The in row is the same wobble the other way round: swings round the dim line that grow bigger, and then a drop onto the green line. The in out row winds up round the dim line, crosses the middle, and wobbles round the green line. The first frame, which is all a viewer that cannot animate shows, is the finished picture: every dot, drawing the whole of each curve.
A real capture, 27 frames played in a loop - three small graphs, one above the other, labeled in, out and in out. In each one a ball moves steadily to the right while its height on the screen is the number being tweened: a dim dashed line at the top is where the number starts, a green dashed line below it is where it ends, and a trail of dots shows where the ball has been. In the out row the ball shoots down past the green line by a long way and then wobbles up and down round it with smaller and smaller swings until it rests on it, like a spring let go. The in row is the same wobble the other way round: swings round the dim line that grow bigger, and then a drop onto the green line. The in out row winds up round the dim line, crosses the middle, and wobbles round the green line. The first frame, which is all a viewer that cannot animate shows, is the finished picture: every dot, drawing the whole of each curve.

The same tween three ways, one row for each of EASE_ELASTIC_IN, EASE_ELASTIC_OUT and EASE_ELASTIC_IN_OUT. The ball's height is the number (like tween_to(y, ...) moving something down), and it drifts right at a steady speed only so that the shape can be seen. The dim line is where the number starts and the green line is where it ends: the ball goes a long way past the green line (and, for the in, behind the dim one). Real pictures from a Game Boy Advance ROM, 4 frames apart, played at the speed of the console. A viewer that does not animate shows the first picture, the finished one.

Example

tween_to(x, x + 100, 90, EASE_ELASTIC_IN_OUT);

The walker wobbles a little either side of where it started, swings across, goes about 12 pixels past the spot 100 pixels away, wobbles round it, and rests exactly there.

Gentler than the plain in or out, because its swings are smaller (about 12% instead of 37%). Good for a move between two places where you want a rubbery feel at both ends.

Cost

An elastic curve does more maths than the others: a sine and a fading factor on every frame it is read. That is fine for the handful of tweens a screen has at once, and a game that uses none of the elastic curves is not made any slower by them.

See also: tweentween_totween_from_to